﻿<Window x:Class="AppToolkit.WPF.UI.ErrorReportDialog"
    x:Name="dlgWindow"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:cnv="clr-namespace:AppToolkit.WPF.UI.Converters"
        
    DataContext="{Binding ElementName=dlgWindow, Path=CurrentException}"
    Title="ErrorReportDialog" Width="600" MinWidth="300" MinHeight="200" Height="Auto" MaxHeight="650" SizeToContent="Height"
        ResizeMode="NoResize" WindowStyle="ToolWindow">
    <Window.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="DialogResources.xaml"/>
            </ResourceDictionary.MergedDictionaries>
            <!-- Converters -->
            <cnv:ExceptionTypeConverter x:Key="_ExceptionTypeConverter" />
            <cnv:StackTraceToArrayConverter x:Key="_StackTraceConverter" />

            <!-- StackTrace DataTemplate -->
            <DataTemplate x:Key="StackTraceTemplate">
                <TextBlock Text="{Binding}" />
            </DataTemplate>

            <ContextMenu x:Key="ctxMenu">
                <MenuItem Command="ApplicationCommands.Copy" />
            </ContextMenu>
        </ResourceDictionary>
    </Window.Resources>
    <Window.CommandBindings>
        <CommandBinding Command="NavigationCommands.BrowseBack" Executed="OnNavigateBack" CanExecute="OnCanNavigateBack" />
        <CommandBinding Command="NavigationCommands.BrowseForward" Executed="OnNavigateForeward" CanExecute="OnCanNavigateForeward" />
        <CommandBinding Command="ApplicationCommands.Copy" Executed="OnCopy" />
        <CommandBinding Command="ApplicationCommands.SaveAs" Executed="OnSaveAs" />
    </Window.CommandBindings>

    <DockPanel Margin="3" ContextMenu="{StaticResource ctxMenu}" LastChildFill="True">
        <!-- Oberer Messageblock -->
        <StackPanel Orientation="Vertical" DockPanel.Dock="Top">
            <Border CornerRadius="6" BorderBrush="{DynamicResource BorderBrush}" BorderThickness="2">
                <DockPanel LastChildFill="True">
                    <TextBlock Margin="3" DockPanel.Dock="Left" Text="Exception Type:" Padding="2" 
                               Background="{DynamicResource ControlBackgroundHighlighted}" 
                               FontWeight="Bold" Width="100" TextAlignment="Right"></TextBlock>
                    <TextBox Name="txtExceptionType" Margin="2" IsReadOnly="True" 
                             Text="{Binding Converter={StaticResource _ExceptionTypeConverter}, Mode=OneWay}"
                             TextWrapping="WrapWithOverflow" ScrollViewer.VerticalScrollBarVisibility="Auto"
                             Background="{DynamicResource ControlBackground}" Padding="1" />
                </DockPanel>
            </Border>
            <DockPanel LastChildFill="True" MaxHeight="250">
                <TextBlock Margin="5,3,3,3" Padding="2" Width="100" Text="Message:"
                           Background="{DynamicResource ControlBackgroundHighlighted}" 
                           FontWeight="Bold" TextAlignment="Right" />
                <TextBox Name="txtMessage" Margin="3" Text="{Binding Path=Message, Mode=OneWay}"
                         IsReadOnly="True" TextWrapping="WrapWithOverflow" 
                         HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
                         Background="{DynamicResource ControlBackground}"  />
            </DockPanel>
            <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="2">
                <Button Margin="3" Width="40" Name="btnNavigateOuterException" Command="NavigationCommands.BrowseBack"
                        ToolTip="Navigate to outer Exception">&lt;&lt;</Button>
                <Button Margin="3" Width="40" Name="btnNavigateInnerException" Command="NavigationCommands.BrowseForward"
                        ToolTip="Navigate to inner Exception">&gt;&gt;</Button>
            </StackPanel>
        </StackPanel>
        
        <!-- Untere Buttonleiste -->
        <StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="2" DockPanel.Dock="Bottom">
            <Button Margin="3,3,3,3" Width="Auto" Name="btnCopyToClipboard" Command="ApplicationCommands.Copy" Padding="4,2">Copy to Clipboard</Button>
            <Button Margin="3,3,9,3" Width="100" Name="btnSaveToFile" Command="ApplicationCommands.SaveAs" Padding="2">Save to File</Button>
            <Button Margin="3" Width="80" Name="btnIgnore" Click="OnBtnIgnoreClick" Padding="2">Ignore</Button>
            <Button Margin="3" Width="80" Name="btnAbort" Click="OnBtnAbortClick" Padding="2">Abort</Button>
        </StackPanel>

        <!-- Stacktrace Expander -->
        <Border Name="outerBorder" CornerRadius="6" 
                    BorderBrush="{DynamicResource BorderBrush}" BorderThickness="2">
            <Expander IsExpanded="True" Margin="3" Name="expDetails" Header="Details" 
                      MaxHeight="{Binding ElementName=outerBorder,Path=Height}">
                <DockPanel LastChildFill="True">
                    <TextBlock Margin="2" Padding="2" FontWeight="Bold" DockPanel.Dock="Top"
                               Background="{DynamicResource ControlBackgroundHighlighted}">Stacktrace</TextBlock>
                    <TextBox Text="{Binding Path=StackTrace, Mode=OneWay}" Margin="3"
                                 HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
                                 Background="{DynamicResource ControlBackground}" />
                    <!--MinHeight="50" MaxHeight="400" -->
                    <!--<ScrollViewer Margin="3" HorizontalScrollBarVisibility="Auto" VerticalScrollBarVisibility="Auto"
                                      MinHeight="50" MaxHeight="300">
                            <TextBlock Text="{Binding Path=StackTrace, Mode=OneWay}" Margin="2" Padding="2" MaxHeight="300"
                                     Background="{DynamicResource ControlBackground}" />
                        </ScrollViewer>-->
                </DockPanel>
            </Expander>
        </Border>


    </DockPanel>
</Window>